package operation;
import java.util.Scanner;
import book.BookList;
import user.admin.Admin;
import user.admin.UserDao;
import user.admin.UserDaoImpl;

public class MemberTest implements IOperation {
    public void work(BookList bl) {
        Scanner input = new Scanner(System.in);
        UserDao ud = new UserDaoImpl();

        System.out.println("请输入用户名：");
        String username = input.nextLine();
        System.out.println("请输入原始密码：");
        String password = input.nextLine();

        boolean isAuthenticated = ud.isLogin(username, password); // 验证用户名和密码

        if (isAuthenticated) {
            System.out.println("原密码正确，请输入新密码：");
            String newPassword1 = input.nextLine();
            System.out.println("请再次输入密码以确认：");
            String newPassword2 = input.nextLine();

            if (newPassword1.equals(newPassword2)) {
                // UserDao 有一个更新密码的方法
                boolean isUpdated = ud.updatePassword(username, newPassword1);
                if (isUpdated) {
                    System.out.println("密码更新成功！");
                } else {
                    System.out.println("密码更新失败，请稍后再试。");
                }
            } else {
                System.out.println("两次密码不一致，无法修改密码。");
            }
        } else {
            System.out.println("用户名或密码错误，无法修改密码。");
        }
    }
}

